﻿
function Login(userName, password, autoLogin, fun_Suc, fun_Err) {
	$.ajax(
        {
        	url: '/User/Login',      // 指定调用的URL，对应于Controller   
        	data: '{UserName:' + userName + ',Password:' + password + ',AutoLogin:' + autoLogin + '}',                            // 如果请求有参数，需要在这里指定   
        	type: "POST",                           // 请求类型   
        	contentType: "application/json;charset=utf-8",
        	dataType: "json",
        	success: function (data) {              // 请求成功后的回调   
        		fun_Suc(data);
        	},
        	error: function (data) {                // 请求失败后的回调   
        		fun_Err(data.statusText);
        	}
        });

}

$(document).ready(function () {
	//debugger
	//预处理TipTxtBox
	readyTipTxtBox();

	$(document).bind("geoPositionSucess", onGeoPositionSucess);

	//处理地理位置
	getGeoPosition();
	//getGeoPosition2();
})
$(window).scroll(function () {
})
function onGeoPositionSucess(event, position) {
	//alert(position.country + position.region + position.city + position.local);
}

//处理地理位置
function getGeoPosition() {
	//debugger
	google.load("maps", "2", { "callback": loadSucess, "language": "zh-cn" });
}
function loadSucess(position) {
	//debugger
	var g = new GClientGeocoder();
	var location = google.loader.ClientLocation;
	if (location) {
		var glatlng = new GLatLng(google.loader.ClientLocation.latitude, google.loader.ClientLocation.longitude);
		//var glatlng = new GLatLng(32.694866, 131.220703);
		g.getLocations(glatlng, geoCallback);
	}
}
function geoCallback(position) {
	var country = "", region = "", city = "", local = "";
	try {
		var place = position.Placemark[0];
		country = place.AddressDetails.Country.CountryName;
		region = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
		city = place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName;
		local = place.AddressDetails.Country.AdministrativeArea.Locality.DependentLocality.DependentLocalityName;
	}
	catch (e)
		{ }
	var pos = { country: country, region: region, city: city, local: local };
	//alert(country + region + city + local);
	$(document).trigger("geoPositionSucess", [pos]);
	// debugger
}

//预处理TipTxtBox
function readyTipTxtBox() {
	var tipTxtBoxs = $("input[tip]");
	for (var i = 0; i < tipTxtBoxs.length; i++) {
		var txtBox = $(tipTxtBoxs[i]);
		txtBox.attr("value", txtBox.attr("tip"));
		txtBox.css("color", "#cccccc");
	}
	tipTxtBoxs.bind("focus", function () {
		$(this).css("color", "black");
		if ($(this).attr("ispwdtip") == "true") {
			//debugger
			$(this).css("display", "none");
			$(this).next().css("display", "block");
			$(this).next().focus();
		}
		if ($(this).attr("value") == $(this).attr("tip"))
			$(this).attr("value", "");
	})
	tipTxtBoxs.bind("blur", function () {
		if ($(this).attr("value") == "") {
			$(this).attr("value", $(this).attr("tip"));
			$(this).css("color", "#cccccc");
			if ($(this).attr("type") == "password") {
				//debugger
				$(this).css("display", "none");
				if ($(this).prev().attr("ispwdtip")) {
					$(this).prev().css("display", "block");
				}
			}
		}
	})
	//		debugger
}


//	function getGeoPosition2() {
//		$.ajax({
//			url: 'http://www.google.com.hk/loc/json',
//			data: '{"version": "1.1.0","host": "maps.google.com","request_address": true,"address_language": "zh-CN"}',
//			type: 'GET',
//			contentType: "application/json;charset=utf-8",
//			dataType: "json",
//			success: function (data) {              // 请求成功后的回调   
//				debugger
//			},
//			error: function (data) {                // 请求失败后的回调   
//				debugger
//			}
//		});
//	}

function AddFav(el, title, commitUrl) {
	url = getFavLink(commitUrl);
	try {
//		if (window.sidebar) {
//			//alert("sidebar");
//			debugger
//			alert(window.sidebar.addPanel(title, url, ""));
//			return;
//		} else 
		if (document.all) {
			//alert("document");
			window.external.AddFavorite(url, title);
			return;
		}
	}
	catch (ex) {

	}
	debugger
	var html = '<a href="' + url + '">' + title + '</a>';
	$(el).replaceWith(html);
}
function getFavLink(commitUrl) {
	var link = "javascript:location.href='" + commitUrl + "?url='+escape(location.href)+'&title='+escape(document.title)";
	return link;
}